{# **
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * #}

{% block material_choice_tree_widget %}
  <div class="material-choice-tree-container js-choice-tree-container{% if required %} required{% endif %}" id="{{ form.vars.id }}">
    <div class="choice-tree-actions">
      <span class="form-control-label js-toggle-choice-tree-action"
            data-expanded-text="{{ 'Expand'|trans({}, 'Admin.Actions') }}"
            data-expanded-icon="expand_more"
            data-collapsed-text="{{ 'Collapse'|trans({}, 'Admin.Actions') }}"
            data-collapsed-icon="expand_less"
            data-action="expand"
      >
        <i class="material-icons">expand_more</i>
        <span class="js-toggle-text">{{ 'Expand'|trans({}, 'Admin.Actions') }}</span>
      </span>
    </div>

    <ul class="choice-tree">
      {% for choice in choices_tree %}
        {{ block('material_choice_tree_item_widget') }}
      {% endfor %}
    </ul>
  </div>

  {{- block('form_help') -}}
{% endblock material_choice_tree_widget %}

{% block material_choice_tree_item_widget %}
  {% set has_children = choice[choice_children] is defined %}

  <li class="{% if choice.has_selected_children %}expanded{% elseif has_children %}collapsed{% endif %}">
    {% if multiple %}
      {{ block('material_choice_tree_item_checkbox_widget') }}
    {% else %}
      {{ block('material_choice_tree_item_radio_widget') }}
    {% endif %}

    {% if has_children %}
      <ul>
        {% for item in choice[choice_children] %}
          {% set choice = item %}
          {{ block('material_choice_tree_item_widget') }}
        {% endfor %}
      </ul>
    {% endif %}
  </li>
{% endblock material_choice_tree_item_widget %}

{% block material_choice_tree_item_checkbox_widget %}
  <div class="checkbox js-input-wrapper">
    <div class="md-checkbox md-checkbox-inline">
      <label>
        <input type="checkbox"
         {% if choice[choice_value] is not null %}
           name="{{ form.vars.full_name }}[]"
           value="{{ choice[choice_value] }}"
           {% if choice[choice_value] in selected_values %}checked{% endif %}
         {% endif %}
         {% if disabled or choice[choice_value] in disabled_values %}disabled{% endif %}
        >
        <i class="md-checkbox-control"></i>
        {{ choice[choice_label] }}
      </label>
    </div>
  </div>
{% endblock material_choice_tree_item_checkbox_widget %}

{% block material_choice_tree_item_radio_widget %}
  <div class="radio js-input-wrapper form-check form-check-radio">
    <label class="form-check-label">
      <input type="radio"
       name="{{ form.vars.full_name }}"
       value="{{ choice[choice_value] }}"
       {% if choice[choice_value] in selected_values %}checked{% endif %}
       {% if disabled or choice[choice_value] in disabled_values %}disabled{% endif %}
       {% if required %}required{% endif %}
      >
      <i class="form-check-round"></i>
      {{ choice[choice_label] }}
    </label>
  </div>
{% endblock material_choice_tree_item_radio_widget %}
